package com.ruoyi.business.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.business.domain.Course;
import com.ruoyi.business.mapper.CourseMapper;
import com.ruoyi.business.service.ICourseService;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements ICourseService {

    @Resource
    private CourseMapper courseMapper;


    public List<Course> getCourseList(Course course) {
        return courseMapper.selectCourseList(course);
    }

    public List<Course> getAllCourseList() {
        return courseMapper.selectAllCourseList();
    }

    public List<Course> getCourseListByCoachIdAndTime(Course course) {
        return courseMapper.selectCourseListByCoachIdAndTime(course);
    }

    public List<Course> getCourseListByCoachId(Course course) {
        return courseMapper.selectCourseListByCoachId(course);
    }

    public List<Course> getCourseByNameAndStartDate(Course course) {
        return courseMapper.selectCourseByNameAndStartDate(course);
    }

    public Course getCourseBySortAndStartDate(Course course) {
        return courseMapper.selectCourseBySortAndStartDate(course);
    }

    @Override
    public List<Course> getCourseByTimeRange(String startTime, String endTime) {
        System.out.println("开始时间：" + startTime);
        System.out.println("结束时间：" + endTime);
        return courseMapper.selectCourseByTimeRange(startTime, endTime);
    }

    public Course getCourseById(Long id) {
        return courseMapper.selectCourseById(id);
    }

    @Override
    public int insertCourse(Course course) {
        return courseMapper.insertCourse(course);
    }

    @Override
    public String insertBatchCourse(List<Course> courses, String operName) {
        for (Course course : courses) {
            Course courseOld = courseMapper.selectCourseBySortAndStartDate(course);
            if (StringUtils.isNull(courseOld)) {
                courseMapper.insertCourse(course);
            } else {
                course.setId(courseOld.getId());
                course.setUpdateBy(operName);
                courseMapper.updateCourse(course);
            }
        }
        return "批量复制成功";
    }

    @Override
    public int updateCourse(Course course) {
        return courseMapper.updateCourse(course);
    }

    @Override
    public Course getCourseById(long id) {
        return courseMapper.selectById(id);
    }

    @Override
    public List<Course> getCourseByVenueId(long venueId) {
        return courseMapper.selectCourseByVenueId(venueId);
    }

    ;

    @Override
    public List<Course> getCourseByCoachId(long coachId) {
        return courseMapper.selectCourseByCoachId(coachId);
    }

    ;

    @Override
    public List<Course> getBannerCourse() {
        return courseMapper.selectBannerCourse();
    }

    @Override
    public List<Course> getCourseByDateAndType(Course course) {
        return courseMapper.selectCourseByDateAndType(course);
    }

    @Override
    public int deleteCurseByIds(Long[] ids) {
        return courseMapper.deleteCurseByIds(ids);
    }

    ;
}
